import {createRouter, createWebHistory} from "vue-router"
import Home from "@/view/home.vue"
import {useStore} from "@/pinia/index.js";
const routes=[
	{
		path:"/",
		component:Home
	},
	{
		path:"/login",
		component:()=>import("@/view/login.vue")
	},
	{
		path:"/reg",
		component:()=>import("@/view/reg.vue")
	}

]
export const router=createRouter({
	routes,
	history:createWebHistory()
})
const whitelist=[
	"/login",
	"/reg"
]
router.beforeEach((to, from,next) => {
	const store=useStore();
	if(!whitelist.includes(to.path)&&store.isLogin===false){
		next("/login")
	}else{
		next()
	}
  })